package dep.web.servlet;

import dep.dao.impl.AdminDao;
import org.dom4j.Document;
import org.dom4j.io.XMLWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class Admin extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AdminDao adminDao = new AdminDao();
        try {
            Document user = adminDao.getUser();
            resp.setContentType("text/xml;charset=GBK");
            PrintWriter writer = resp.getWriter();
            XMLWriter xmlWriter = new XMLWriter(writer);
            xmlWriter.write(user);
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
